package cn.piaoyi.fio.imp;

import java.io.*;

import org.apache.commons.io.*;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.piaoyi.comm.Constant;
import cn.piaoyi.comm.ImgUtil;
import cn.piaoyi.comm.PiaoyiUtil;
import cn.piaoyi.fio.PicUploadFile;
import cn.piaoyi.fio.UploadFile;

public class PicUploadFileImp implements PicUploadFile {
	private static final Log logger = LogFactory.getLog(PicUploadFileImp.class);	

  public PicUploadFileImp() {
  }

  /**
  *
  * @param toFileName String
  * @param uploadFile UploadFile
  * @param sysConfig SysConfig
  * @throws IOException
  */
 public String saveUploadFile(UploadFile uploadFile) throws IOException {
	 	String basePath = PiaoyiUtil.mkDirByNow(Constant.PIC_PATH);
	 	String ext = FilenameUtils.getExtension(uploadFile.getFileName());
		String formjpg =basePath + "/" +  System.currentTimeMillis() + RandomStringUtils.randomNumeric(4) + "." + ext;
		OutputStream bos = new FileOutputStream(Constant.ROOTPATH + "/" + formjpg);
		IOUtils.copy(uploadFile.getInputStream(), bos);
		bos.close();
		uploadFile = null;
		String newformjpg = basePath + "/" +  System.currentTimeMillis() + RandomStringUtils.randomNumeric(4) + "_logo." + ext;
		//加水印
		//ImgUtil.pressImage(new File(Constant.ROOTPATH + "/" + formjpg),Constant.ROOTPATH + "/" + formjpg,ext,Constant.ROOTPATH + "/images/logo.jpg");
		return formjpg;
 }
 
 
 public static void main(String[] args) throws Exception {
	 File f = new File("d:/small.jpg");
	 if(f.isFile()){
		 System.out.println("yes");
	 }else{
		 System.out.println("no");
	 }
 }
}
